package code.ui
{
	import code.utils.MaterialUtil;
	
	import com.darwin.darwinDisplay.DarBitmapMovieClip;
	import com.darwin.darwinDll.Dll;
	import com.darwin.darwinDll.core.DllItem;
	import com.darwin.darwinUI.core.UIComponent;
	import com.darwin.darwinUI.manager.ToolTipManager;
	import com.darwin.darwinUI.manager.UIManager;
	
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	import module.building.consts.BuildConst;
	import module.building.event.BuildEvent;
	import module.main.view.ResourceConst;
	
	/**
	 * 环形菜单 单个选项基类 
	 * @author sam
	 * 
	 */	
	public class BaseRingItem extends UIComponent
	{
		
		private var itemBg:DarBitmapMovieClip;
		private var bgSource:DisplayObject;
		private var itemType:int;
		private var typeStr:String;
		/**
		 *资源名 
		 */		
		private var souseStr:String;
		
		public function BaseRingItem(type:int,itemBgSource:DisplayObject = null)
		{
			
			super();
			this.width = 45.0;
			this.height = 45.0;
			bgSource = itemBgSource;
			itemType = type;
			this.addEventListener(MouseEvent.CLICK,clickHandler);
			this.addEventListener(MouseEvent.MOUSE_OVER,showTipHandler);
			init();
		}
		
		private function init():void{
			initTip();
			initBg();
		}
		
		private function initTip():void{
			switch(itemType){
				case BuildConst.BUILD_REPAIR:
					typeStr = "维修";
					souseStr = ResourceConst.CIRCLE_SERVICE;
					break;
				case BuildConst.BUILD_UPDATA:
					typeStr = "升级";
					souseStr = ResourceConst.CIRCLE_LEVEL_UP;
					break;
				case BuildConst.BUILD_EDIT:
					typeStr = "编辑部队";
					souseStr = ResourceConst.CIRCLE_EDIT_TROOP;
					break;
				case BuildConst.BUILD_RECRIUT:
					typeStr = "招募裸兵";
					souseStr = ResourceConst.CIRCLE_RECRIUT_SODIER;
					break;
				case BuildConst.BUILD_ARCHER_EQUIP:
					typeStr = "弓兵装备生产";
					souseStr = ResourceConst.CIRCLE_ARCHER_EQUIP;
					break;
				case BuildConst.BUILD_INFANTRY_EQUIP:
					typeStr = "步兵装备生产";
					souseStr = ResourceConst.CIRCLE_INFANTRY_EQUIP;
					break;
				case BuildConst.BUILD_CAVALRY_EQUIP:
					typeStr = "骑兵装备生产";
					souseStr = ResourceConst.CIRCLE_CAVALRY_EQUIP
					break;
				case BuildConst.BUILD_KNIGHT_RECRIUT:
					typeStr = "招募骑士";
					souseStr = ResourceConst.CIRCLE_KNIGHT_RECRIUT;
					break;
				case BuildConst.BUILD_KNIGHT_MANAGE:
					souseStr = ResourceConst.CIRCLE_KNIGHT_MANAGE;
					typeStr = "骑士管理";
					break;
				case BuildConst.BUILD_FARM:
					souseStr = ResourceConst.CIRCLE_BUILD_FARM;
					typeStr = "种植";
					break;
				case BuildConst.BUILD_GATE:
					souseStr = ResourceConst.CIRCLE_SERVICE;
					typeStr = "城门开关";
					break;
				case BuildConst.BUILD_NAKED_SOLDIERS_HARVEST:
					souseStr = ResourceConst.CIRCLE_RECRIUT_SODIER;
					typeStr = "裸兵即时收获";
					break;
				case BuildConst.BUILD_ARCHER_IMMEDIATELY_HARVEST_EQUIPMENT:
					souseStr = ResourceConst.CIRCLE_ARCHER_EQUIP;
					typeStr = "弓箭兵装备即时收获";
					break;
				case BuildConst.BUILD_CAVALRY_IMMEDIATELY_HARVEST_EQUIPMENT:
					souseStr = ResourceConst.CIRCLE_CAVALRY_EQUIP;
					typeStr = "骑兵装备即时收获";
					break;
				case BuildConst.BUILD_INFANTRY_IMMEDIATELY_HARVEST_EQUIPMENT:
					souseStr = ResourceConst.CIRCLE_INFANTRY_EQUIP;
					typeStr = "步兵装备即时收获";
					break;


				default:
					typeStr = "无配置";
					souseStr = ResourceConst.CIRCLE_SERVICE;
					break;
						
			}
		}
		
		private function showTipHandler(e:MouseEvent):void{
			UIManager.getToolTipManager().showTips(SimpleToolTips,e.target,typeStr,ToolTipManager.UP);
		}
		
		private function setViewData():void{
			
		}
		
		private function clickHandler(e:MouseEvent):void{
			var obj:Object = {type:itemType}
			var event:BuildEvent = new BuildEvent(BuildEvent.BUILD_RING_ITEM_CLICK,obj,true);
			dispatchEvent(event);
		}
		
		/**
		 * 初始化背景 
		 * 
		 */		
		private function initBg():void{
			if(bgSource==null){
				var c:Class = Dll.getInstance().getSynPreloadRes("",ResourceConst.BUILDING_RING_ICON,DllItem.TYPE_SWF);
				itemBg = new DarBitmapMovieClip(c);
			}else{
				itemBg = new DarBitmapMovieClip(bgSource)
			}
			addChild(itemBg);
			var spItem:Sprite = MaterialUtil.getPreloadMaterial("uiCircle",souseStr) as Sprite;
			spItem.x = (this.width - spItem.width) / 2;
			spItem.y = (this.height - spItem.height) / 2;
			spItem.mouseEnabled = false;
			spItem.mouseChildren = false;
			this.addChild(spItem);
		}
		
		public function data():void{
			
		}
	}
}